package com.gsn.common;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.ClickListener;
import com.badlogic.gdx.scenes.scene2d.ui.GsnImageButton;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.gsn.desktop.engine.ActorUtility;
import com.gsn.engine.gdx.GsnParticleActor;
import com.gsn.engine.myplay.GsnLayer;
import com.gsn.poker.asset.PokerSound;
import com.gsn.poker.asset.PortalTexture;

public class PortalCommingLayer extends GsnLayer implements ClickListener {
	private static final String tag = "DialogLayer";
	float time = 0.5f;
	protected ParticleEffect clickEff;

	public PortalCommingLayer(float width, float height) {
		super(width, height);

		Image bgDark = new Image(PortalTexture.inst().bgDarkDialog);
		PortalTexture.inst().scaleActor(bgDark);
		addActor(bgDark);
		bgDark.width = width;
		bgDark.height = height;

		Image bg = new Image(PortalTexture.inst().bgDialog);
		PortalTexture.inst().scaleActor(bg);
		addActor(bg);
		bg.x = (width - bg.width) / 2;
		bg.y = (height - bg.height) / 2;

		Image comming = new Image(PortalTexture.inst().iconCuComming);
		PortalTexture.inst().scaleActor(comming);
		addActor(comming);
		comming.x = (width - comming.width) / 2;
		comming.y = (height - comming.height) / 2;

		GsnImageButton close = new GsnImageButton(PortalTexture.inst().closeButton, PortalTexture.inst().closeButtonPress);
		PortalTexture.inst().scaleActor(close);
		addActor(close);
		close.x = bg.x + bg.width - close.getRealWidth() * 1.4f;
		close.y = bg.y + bg.height - close.getRealHeight() * 1.1f;
		close.setClickListener(this);

		clickEff = PortalTexture.inst().clickEff;
	}

	@Override
	public void click(Actor actor, float x, float y) {
		// TODO Auto-generated method stub
		hide();
		PokerSound.playClick();
		if (clickEff != null) {
			Vector2 v = ActorUtility.getCoordinate(actor, x, y, this.root);
			GsnParticleActor par = new GsnParticleActor(clickEff);
			par.setPostition(v.x, v.y);
			par.start();
			this.addActor(par);
		}

	}

	public InputProcessor oldInput;

	public void show() {
		oldInput = Gdx.input.getInputProcessor();
		visible = true;
		setInputListener();
	}

	public void hide() {
		Gdx.input.setInputProcessor(oldInput);
		oldInput = null;
		visible = false;
	}

}
